package top.zhaoyuliu.logbook.client.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;

/**
 * 
 * Copyright © 2021 Arain. All rights reserved.
 *
 * @Title: ApplicationContextProvider.java
 * @Prject: logbook-client
 * @Package: top.zhaoyuliu.logbook.client.utils
 * @Description: <功能详细描述>
 * @author: Arain  
 * @date: 2021年1月23日 下午1:32:16
 * @version: V1.0
 */
public class ApplicationContextProvider implements ApplicationContextAware {
    private static ApplicationContext context;

    public static ApplicationContext getApplicationContext() {
        return context;
    }

    @Override
    public void setApplicationContext(ApplicationContext ac)
            throws BeansException {
        context = ac;
    }

    public static <T> T getBean(Class<T> tClass) {
        return context.getBean(tClass);
    }

    public static <T> T getBean(String name, Class<T> tClass) {
        return context.getBean(name, tClass);
    }

    public static void publishEvent(ApplicationEvent event) {
        context.publishEvent(event);
    }
}
